/**
 *继承cc.component 的单例
 */
var game_mgr = require("game_mgr");
var evemt_mgr = require("event_mgr");
var res_mgr = require("res_mgr");
var login_scene = require("login_scene");

var game_app = cc.Class({
    extends: game_mgr,

    statics:{
        Instance: null,  //类的静态成员
    },


    properties: {
    },

    // LIFE-CYCLE CALLBACKS:
    onLoad() {
        if (game_app.Instance === null) {
            game_app.Instance = this;
        } else {//保证全局唯一
            cc.error("[error:] game_app has multi instances!!!");
            this.destroy();
            return;
        }
        game_mgr.prototype.onLoad.call(this);
    
    },


    start() {
        cc.log("=======game_app start==========")
        // this.enter_login_scene();

        // //测试事件订阅者模块
        // //注册事件
        // evemt_mgr.add_event_listenenr("beginn_game",this, this.on_beigin_call);
        // evemt_mgr.add_event_listenenr("beginn_game",this, this.on_beigin_call);
        // evemt_mgr.add_event_listenenr("beginn_game",this, this.on_beigin_call);
        // evemt_mgr.add_event_listenenr("beginn_game",this, this.on_beigin_call);
        // evemt_mgr.add_event_listenenr("beginn_game",this, this.on_beigin_call);
        // //删除事件
        // event_mgr.remove_event_listener("beginn_game",this,this.on_beigin_call);
        // event_mgr.remove_event_listener("beginn_game",this,this.on_beigin_call);
        // event_mgr.remove_event_listener("beginn_game",this,this.on_beigin_call);
        // event_mgr.remove_event_listener("beginn_game",this,this.on_beigin_call);
        // event_mgr.remove_event_listener("beginn_game",this,this.on_beigin_call);
        // //发射事件
        // event_mgr.dispatch_event("beginn_game", "hello_event");
        // //end

      
        //测试资源加载模块
        // var pkg = {
		// 	prefabs: [
		// 		"ui_prafabs/LoginUI", 
		// 	],
		// };
        // res_mgr.Instance.preload_res_pkg(pkg,(pre)=>{
        //     cc.log("=====pre==========",pre);
        // },()=>{
        //     cc.log("finish " ,this);
        //     var ui = cc.instantiate(res_mgr.Instance.get_res("ui_prafabs/LoginUI"));
		// 	this.canvas.addChild(ui);
        // })        
		// this.scheduleOnce(function() {
		// 	// res_mgr.Instance.release_res_pkg(pkg);
		// }.bind(this), 5);
        //end

        //测试场景管理器
        this.preload_scene(login_scene,()=>{
            console.log("=======加载资源中=========");
        },()=>{
            console.log("=======preload_scene============")
            this.enter_scene(login_scene);

            // this.scheduleOnce(()=>{
            //     this.enter_scene(login_scene);
            // },5)
        })
        //end

    },


    on_beigin_call(event_name, udata){
        cc.log(this, "on_begin_call: " + event_name + " udata: " + udata);
    },

    //场景的逻辑放在这里
    enter_login_scene() {
        //放地图
        //...

        //放角色
        //...

        //放UI
        //end

        console.log("======game_app.Instance======",game_app.Instance);
    },

    enter_home_scene() {

    },

    enter_game_scene() {

    },

    // update (dt) {},
});
